;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var router = require("../hash/pageRouter");
	var databind = require("databind");
	var css_riskWarning = require("./warningSchemeCreate.css");
	var html_enterprise_list = require("./html_enterprise_list.html");
	var html_memberGrade_list = require("./html_memberGrade_list.html");
	var tools = require("tools");
	var css_dialog = require("css_dialog");
	var schemeId;
	var oData1 = {
		pageIndex: 1,
		pageSize: 10, 
		totalPageCount: 1, 
		totalRecordCount: 0,
		enabled: true
	};
	
	var oData2 = {
		pageIndex: 1,
		pageSize: 10, 
		totalPageCount: 1, 
		totalRecordCount: 0,
		state: 1
	};
	var tools = require("tools");
	var init = function(page) {
		if (page.params != null && page.params.schemeId != null) {
			schemeId = page.params.schemeId;
			databind.fillInput1($("#warningSchemeCreate"), {action: "inquireWarningSchemeDetail.json?schemeId=" + schemeId}, function(){
				databind.disableInput($("#warningSchemeCreate"));
				$("#submitWarningScheme").hide();
				$("#warningSchemeCreate .updateWarningScheme").removeClass("none");
			});
		}
		initEvent();
		router.init();
	};
	
	var initEvent = function() {
		// 若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == ""|| base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		$("#submitWarningScheme").unbind("click").click(function(){
			databind.submitDom($("#warningSchemeCreate"), function(){
				base.alert(1, "保存成功！");
				router.route("auditWarning/warningSchemeList.html");
			});
		});
		
		$("#warningSchemeCreate .updateWarningScheme").unbind("click").click(function(){
			databind.enableInput($("#warningSchemeCreate"));
			$("#submitWarningScheme").show();
			$("#warningSchemeCreate").attr("action", "updateWarningScheme");
		});
		
		//点击选择企业
		$("#warningSchemeCreate input[name=enterpriseName]").unbind("click").click(function(){
			$("#popdialog").html(html_enterprise_list);
			tools.loadList("inquireEnterprisePageList.json", $("#htmlEnterpriseListTable"), $("#htmlEnterpriseListTpl"), oData1, function(){
				
			});
			dialog.showDialog($("#enterprise_list_dialog"));
			
			$("#enterprise_list_dialog #enterpriseListSearchButton").unbind("click").click(function(){
				oData1.pageIndex = 1;
				oData1.pageSize = 10; 
				oData1.totalPageCount = 1; 
				oData1.totalRecordCount = 0;
				oData1.createDateTimeBegin = $("#enterprise_list_dialog .createDateTimeBegin").val();
				oData1.createDateTimeEnd = $("#enterprise_list_dialog .createDateTimeEnd").val();
				oData1.enterpriseName = $("#enterprise_list_dialog .enterpriseName").val();
				tools.loadList("inquireEnterprisePageList.json", $("#htmlEnterpriseListTable"), $("#htmlEnterpriseListTpl"), oData1, function(){
					
				});
			});
			
			$("#enterprise_list_dialog .sure_yes").unbind("click").click(function(){
				var eName = $("#enterprise_list_dialog input[name=enterpriseListRadio]:checked").parents("tr").attr("enterpriseName");
				var eId = $("#enterprise_list_dialog input[name=enterpriseListRadio]:checked").parents("tr").attr("enterpriseId");
				$("#warningSchemeCreate input[name=enterpriseName]").val(eName);
				$("#warningSchemeCreate input[name=enterpriseId]").val(eId);
				dialog.hideDialog($("#enterprise_list_dialog"));
			});
			
			$("#enterprise_list_dialog .sure_no").unbind("click").click(function(){
				dialog.hideDialog($("#enterprise_list_dialog"));
			});
		});
		
		//点击选择等级
		$("#warningSchemeCreate input[name=gradeName]").unbind("click").click(function(){
			$("#popdialog").html(html_memberGrade_list);
			tools.loadList("inquireMemberGradePageList.json", $("#htmlMemberGradeListTable"), $("#htmlMemberGradeListTpl"), oData2, function(){
				
			});
			dialog.showDialog($("#memberGrade_list_dialog"));
			$("#memberGrade_list_dialog .sure_yes").unbind("click").click(function(){
				var eName = $("#memberGrade_list_dialog input[name=memberGradeListRadio]:checked").parents("tr").attr("gradeName");
				var eId = $("#memberGrade_list_dialog input[name=memberGradeListRadio]:checked").parents("tr").attr("memberGradeId");
				$("#warningSchemeCreate input[name=gradeName]").val(eName);
				$("#warningSchemeCreate input[name=memberGradeId]").val(eId);
				dialog.hideDialog($("#memberGrade_list_dialog"));
			});
			
			$("#memberGrade_list_dialog .sure_no").unbind("click").click(function(){
				dialog.hideDialog($("#memberGrade_list_dialog"));
			});
		});
		
		$("#warningSchemeCreate").on("change", "select[name=factor]", function(){
			var $this = $(this);
			if ($this.val() == "0") {
				$("#warningSchemeCreate select[name=valueType]").val("1");
			} else if ($this.val() == "1" || $this.val() == "2" || $this.val() == "3") {
				$("#warningSchemeCreate select[name=valueType]").val("0");
			}
		})
	};
	
	return {
		init : init
	};
});